package pl.ptemich.bumbastic.physics;


import pl.ptemich.bumbastic.Point;


public class Rectangle extends AbstractCollisionShape {

  private int width;
  
  private int height;
  
  
  public Rectangle(Point position, int width, int height) {
    this.setPosition(position);
    this.width = width;
    this.height = height;
  }  

  
  
  @Override
  public boolean checkColision(CollisionShape obj) {
    if (obj instanceof Circle) {
      return checkColision((Circle) obj);
    } else if (obj instanceof Rectangle) {
      return checkColision((Rectangle) obj);
    }
    
    return false;
  }

  public boolean checkColision(Rectangle obj) {    
    
    if ((position.getPosX() + width/2) < (obj.position.getPosX() - obj.width/2)) {
      return false;
    } else if ((position.getPosX() - width/2) > (obj.position.getPosX() + obj.width/2)) {
      return false;
    } else if ((position.getPosY() + height/2) < (obj.position.getPosY() - obj.width/2)) {
      return false;
    } else if ((position.getPosY() - height/2) > (obj.position.getPosY() + obj.width/2)) {
      return false;
    } 
        
    return true;
  }
  
  
  public boolean checkColision(Circle obj) {
    if ((obj.getPosition().getPosX() + obj.getRadius() > (position.getPosX() - width/2)) //from the left 
        && (obj.position.getPosX() - obj.getRadius() < (position.getPosX() + width/2)) //from the right
        && (obj.position.getPosY() + obj.getRadius() > (position.getPosY() - height/2)) //from the bottom
        && (obj.position.getPosY() - obj.getRadius() < (position.getPosY() + height/2))) //from the top
    {
      return true;
    }
    
    return false;
  }



public int getWidth() {
    return width;
}



public int getHeight() {
    return height;
}
  
  
}
